package com.bgate.game;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author user
 */
import javax.microedition.rms.*;

public abstract class BaseRMS {

    private String rmsName;
    private RecordStore recordStore;

    BaseRMS(String rmsName) {
        this.rmsName = rmsName;
    }

    public void open() {
        try {
            recordStore = RecordStore.openRecordStore(this.rmsName, true);
            if (recordStore.getNumRecords() > 0) {
                loadData();
            } else {
                createDefaultData();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int sizeRecordStore() throws RecordStoreNotOpenException{
        return this.recordStore.getSizeAvailable();
    }

    public void close() {
        if (recordStore != null) {
            try {
                recordStore.closeRecordStore();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public RecordStore getRecordStore() {
        return this.recordStore;
    }

    public String getRMSName() {
        return this.rmsName;
    }

    abstract void loadData();

    abstract void createDefaultData();

    abstract void updateData();
}
